/*
 * @Description: app充值业务页面数据管理
 * @Author: tao.xie
 * @Date: 2019-03-19 11:46:47
 * @Last Modified by: tao.xie
 * @Last Modified time: 2019-03-19 16:13:58
 */
import { FAIL, REFUND, SUCCESS, TRADING } from '../constants/TradeState'
import { dateFtt } from 'vue-xiaobu-utils'

/**
 *根据交易状态返回详情数据元素集合
 *
 * @param {*} detailObj
 * @returns
 */
function getInfoListDataByState(detailObj) {
  let state = detailObj.STATE
  switch (state) {
    case FAIL:
      return getInfoListDataWhenFail(detailObj)
    case REFUND:
      return getInfoListDataWhenRefund(detailObj)
    case SUCCESS:
      return getInfoListDataWhenSuccess(detailObj)
    case TRADING:
      return getInfoListDataWhenTrading(detailObj)
    default:
      break
  }
}

/**
 *充值失败的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenFail(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    centerMsg: '充值失败'
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *充值已提现的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenRefund(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    centerMsg: '已提现'
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *充值成功的页面数据管理
 *
 * @param {*} detailObj
 * @returns
 */
function getInfoListDataWhenSuccess(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '充值成功',
    infoValue: '+' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  // 代充用户的解析显示
  let isother = detailObj.IS_OTHER === 1
  if (isother && detailObj.NICK_NAME) {
    copyinfolist.push({ infoName: '代充用户', infoValue: detailObj.NICK_NAME })
  }
  copyinfolist.push({ infoName: '支付方式', infoValue: detailObj.PAYMENT_NAME })
  return copyinfolist.concat(getCommonListData(detailObj))
}
/**
 *充值中的页面数据管理
 *
 * @param {*} detailObj
 */
function getInfoListDataWhenTrading(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '待充值',
    infoValue: '+' + detailObj.PAY_FEE.toFixed(2),
    isInfoValueStress: true
  })
  return copyinfolist.concat(getCommonListData(detailObj))
}

/**
 *获取充值业务通用数据
 *
 * @param {*} detailObj
 * @returns
 */
function getCommonListData(detailObj) {
  let copyinfolist = []
  copyinfolist.push({
    infoName: '充值时间',
    infoValue: dateFtt('yyyy年MM月dd日 hh:mm:ss', detailObj.TRADE_TIME)
  })
  copyinfolist.push({
    infoName: '订单流水号',
    infoValue: detailObj.OUT_TRADE_NO
  })
  return copyinfolist
}

export default getInfoListDataByState
